package battle;

import hibernate.HibernateUtil;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;

import entity.CardVo;


public class BattleDao extends HibernateUtil{

	
	static Logger logger = Logger.getLogger(BattleDao.class);
	
	private final SessionFactory sessionFactory = getSessionFactory();


	@SuppressWarnings("unchecked")
	public List<CardVo> getCardList() {
		
		try {
			Session session=sessionFactory.getCurrentSession();			
			session.beginTransaction();			
			List<CardVo> result=session.createCriteria(CardVo.class).list();
			session.getTransaction().commit();			
			return result;
		} catch (RuntimeException re) {
			logger.error(re);
			throw re;
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<CardVo> getCardListByStar(int star){
		try {
			Session session=sessionFactory.getCurrentSession();			
			session.beginTransaction();			
			List<CardVo> result=session.createCriteria(CardVo.class).add(Restrictions.eq("star", star)).list();
			session.getTransaction().commit();			
			return result;
		} catch (RuntimeException re) {
			logger.error(re);
			throw re;
		}
	}

}
